package cn.itcast.exception;

import cn.itcast.pojo.Result;
import com.aliyun.oss.ServiceException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.nio.file.FileSystemException;

@RestControllerAdvice
public class GolbalExceptionHandle {
    //
       /**
     * 处理 ServiceException 异常
     *
     * @param serviceException 服务异常对象
     * @return 包含错误信息的 Result 对象
     */
    @ExceptionHandler(ServiceException.class)
    public Result handleServiceException(ServiceException serviceException){
        // 返回错误结果，错误信息从异常中获取
        return Result.erro(serviceException.getMessage());
    }


    @ExceptionHandler(SystemException.class)
    public Result handleSystemException(SystemException systemException){
        return Result.erro(systemException.getMessage());
    }
//    @ExceptionHandler(Exception.class)
//    public Result Exception(Exception e){
//        return Result.erro("亲亲服务器爆炸了,快跑吧!!!");
//    }

    @ExceptionHandler(MapperException.class)
    public Result handleMapper(MapperException mapperException){
        return Result.erro(mapperException.getMessage());
    }
}
